package hyrpt

class StepStatusAnalysisController {
    def dynamicQueryService
    def stepStatusAnalysis() {
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        def tableHeadList = []
        def stepStatusAnalysis = []
        def pageSizeList = [10, 20, 50, 100]
        def totalCount = 0
        def stepStatusAnalysisSum = [];
        if(params.EXPORT_CONTENT_NAME=='Excel'){
            params.SYS_QUERY_NAME = 'stepStatusAnalysis'
            stepStatusAnalysis = dynamicQueryService.queryForList(params)
            tableHeadList =  []
            if(stepStatusAnalysis.size()>0){
                tableHeadList =  stepStatusAnalysis[0].keySet()
            }
            params.SYS_QUERY_NAME = 'stepStatusAnalysisCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT

        }
        params.SYS_QUERY_NAME = 'stepStatusAnalysisSum'
        stepStatusAnalysisSum = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepList'
        def stepStatusAnalysisStepList = dynamicQueryService.queryForList(params)

        [totalCount:totalCount,tableHeadList:tableHeadList,
         pageSizeList:pageSizeList,
         pageSize:pageSize,
         stepStatusAnalysisSum:stepStatusAnalysisSum,
         startno:params.startno?:'',
         endno:params.endno?:'',
         step:params.step?:'',
         stepStatusAnalysis:stepStatusAnalysis,
         stepStatusAnalysisStepList:stepStatusAnalysisStepList
        ]
    }
    def stepStatusAnalysisStep(){
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        params.stepName=params.stepName
        params.state=params.state
        def pageSizeList = [10,20,50,100]
        println(params)
        def stepStatusAnalysisStep=[]
        def tableHeadList =  []
        def totalCount=0
        def stepStatusAnalysisStepSumQty=[]
        if(params.state=='WAIT'||params.state=='RUN'||params.state=='REPAIR'||params.state=='OUTSRC'){
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStep'
            stepStatusAnalysisStep = dynamicQueryService.queryForList(params)
            print(stepStatusAnalysisStep)
            if(stepStatusAnalysisStep.size()>0){
                tableHeadList =  stepStatusAnalysisStep[0].keySet()
            }
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepSumQty'
            stepStatusAnalysisStepSumQty = dynamicQueryService.queryForList(params)
        }else if(params.state=='SCRAP'){
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepScrap'
            stepStatusAnalysisStep = dynamicQueryService.queryForList(params)
            if(stepStatusAnalysisStep.size()>0){
                tableHeadList =  stepStatusAnalysisStep[0].keySet()
            }
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepScrapCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepScrapSumQty'
            stepStatusAnalysisStepSumQty = dynamicQueryService.queryForList(params)
        }else if(params.state=='HOLD'){
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepHold'
            stepStatusAnalysisStep = dynamicQueryService.queryForList(params)
            if(stepStatusAnalysisStep.size()>0){
                tableHeadList =  stepStatusAnalysisStep[0].keySet()
            }
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepHoldCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepHoldSumQty'
            stepStatusAnalysisStepSumQty = dynamicQueryService.queryForList(params)
        }

        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepPartNameList'
        def stepStatusAnalysisStepPartNameList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepPartDescList'
        def stepStatusAnalysisStepPartDescList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepGroupList'
        def stepStatusAnalysisStepGroupList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepTotalGroupList'
        def stepStatusAnalysisStepTotalGroupList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepDetailCateList'
        def stepStatusAnalysisStepDetailCateList = dynamicQueryService.queryForList(params)


        [totalCount:totalCount,tableHeadList:tableHeadList,
         pageSizeList:pageSizeList,pageSize:pageSize,
         startno:params.startno?:'',endno:params.endno?:'',
         partName:params.partName?:'',stepStatusAnalysisStep:stepStatusAnalysisStep,
         partDesc:params.partDesc?:'',group3:params.group3?:'',totalGroup:params.totalGroup?:'',
         detailCate:params.detailCate?:'',stepName:params.stepName?:'',state:params.state?:'',
         stepStatusAnalysisStepPartNameList:stepStatusAnalysisStepPartNameList,
         stepStatusAnalysisStepPartDescList:stepStatusAnalysisStepPartDescList,
         stepStatusAnalysisStepGroupList:stepStatusAnalysisStepGroupList,
         stepStatusAnalysisStepTotalGroupList:stepStatusAnalysisStepTotalGroupList,
         stepStatusAnalysisStepDetailCateList:stepStatusAnalysisStepDetailCateList,
         stepStatusAnalysisStepSumQty:stepStatusAnalysisStepSumQty
        ]
    }
}
